from web.Script import www_2t58_com
from django.http import JsonResponse

script = www_2t58_com.Script_2t58_com()


# 热门歌手、热门歌单、热门视频、热门歌曲
def get_hot_music(request):
    music_data = script.get_hot()
    return JsonResponse(music_data, safe=False)


# 获取歌手下的音乐
def get_actor_music(request):
    if request.method == 'GET':
        link = request.GET.get('link')
        music_data = script.get_actor_hot_music(link)
        return JsonResponse(music_data, safe=False)
    return JsonResponse({'code': 400, 'msg': '请求方式错误'}, safe=False, status=400)

# 根据音乐链接获取音乐数据
def get_music_link(request):
    if request.method == 'GET':
        link = request.GET.get('link')
        music_data = script.get_music_link(link)
        return JsonResponse(music_data, safe=False)
    return JsonResponse({'code': 400, 'msg': '请求方式错误'}, safe=False, status=400)

# 根据视频链接获取视频
def get_video_link(request):
    if request.method == 'GET':
        link = request.GET.get('link')
        music_data = script.get_video_link(link)
        return JsonResponse(music_data, safe=False)
    return JsonResponse({'code': 400, 'msg': '请求方式错误'}, safe=False, status=400)

# 搜索音乐
def search_music(request):
    if request.method == 'POST':
        keyword = request.GET.get('keyword')
        music_data = script.search_music(keyword)
        return JsonResponse(music_data, safe=False)
    return JsonResponse({'code': 400, 'msg': '请求方式错误'}, safe=False, status=400)

# 新歌榜、TOP榜单、DJ舞曲
def get_music_rank(request):
    if request.method == 'GET':
        types = request.GET.get('types')
        music_data = script.get_music_rank(types)
        return JsonResponse(music_data, safe=False)
    return JsonResponse({'code': 400, 'msg': '请求方式错误'}, safe=False, status=400)

# 筛选歌手
def get_actor(request):
    if request.method == 'GET':
        types = request.GET.get('types', 'index')
        sex = request.GET.get('sex', 'index')
        clas = request.GET.get('clas', 'index')
        As = request.GET.get('As', 'index')
        pages = request.GET.get('pages', 1)
        music_data = script.get_actor(types, sex, clas, As, pages)
        return JsonResponse(music_data, safe=False)
    return JsonResponse({'code': 400, 'msg': '请求方式错误'}, safe=False, status=400)


# 筛选歌单
def get_songe_music_list(request):
    if request.method == 'GET':
        types = request.GET.get('types', 'index')
        pages = request.GET.get('pages', 1)
        music_data = script.get_songe_music_list(types, pages)
        return JsonResponse(music_data, safe=False)
    return JsonResponse({'code': 400, 'msg': '请求方式错误'}, safe=False, status=400)

# 筛选电台
def get_radio(request):
    if request.method == 'GET':
        types = request.GET.get('types', 'index')
        pages = request.GET.get('pages', 1)
        music_data = script.get_radio(types, pages)
        return JsonResponse(music_data, safe=False)
    return JsonResponse({'code': 400, 'msg': '请求方式错误'}, safe=False, status=400)

# 筛选高清MV
def get_hd_mv(request):
    if request.method == 'GET':
        types = request.GET.get('types', 'index')
        pages = request.GET.get('pages', 1)
        music_data = script.get_hd_mv(types, pages)
        return JsonResponse(music_data, safe=False)
    return JsonResponse({'code': 400, 'msg': '请求方式错误'}, safe=False, status=400)